home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: Clipboard.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* This file contains the code for the document procedure pointers for the DTS.Draw
- ** clipboard document. The clipboard document is simply a modified DTS.Draw document.
- ** Many of the main document facilities are removed, since they don't apply to the
- ** clipboard. See ClipboardInitDocument() for a full breakdown of the changes in
- ** the document procedures. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __TREEOBJ2__
- #include "TreeObj2.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern RgnHandle gCursorRgn;
- extern CursPtr gCursorPtr;
-
- static OSErr ClipboardInitContent(FileRecHndl frHndl, WindowPtr window);
- static void ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
- static Boolean ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
- static Boolean ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Initialize the clipboard document. */
-
- #pragma segment ClipboardDoc
- OSErr ClipboardInitDocument(FileRecHndl frHndl)
- {
- OSErr err;
- FileRecPtr frPtr;
-
- err = DefaultInitDocument(frHndl, 0, 0, 0);
- /* Use the hierarchical document architecture. */
-
- if (!err) { /* Set some custom window behaviors, and disable the rest. */
- frPtr = *frHndl;
- frPtr->fileState.calcFrameRgnProc = nil;
- frPtr->fileState.contentClickProc = ClipboardContentClick;
- frPtr->fileState.contentKeyProc = ClipboardContentKey;
- frPtr->fileState.drawFrameProc = nil;
- frPtr->fileState.freeDocumentProc = nil;
- frPtr->fileState.freeWindowProc = nil;
- frPtr->fileState.initContentProc = ClipboardInitContent;
- frPtr->fileState.readDocumentProc = nil;
- frPtr->fileState.readDocumentHeaderProc = nil;
- frPtr->fileState.resizeContentProc = nil;
- frPtr->fileState.scrollFrameProc = nil;
- frPtr->fileState.undoFixupProc = nil;
- frPtr->fileState.windowCursorProc = ClipboardWindowCursor;
- frPtr->fileState.writeDocumentProc = nil;
- frPtr->fileState.writeDocumentHeaderProc = nil;
- }
-
- return(err);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Initialize the clipboard document size. By waiting this late to state the
- ** document size, the window is initially opened to the size described in the
- ** 'WIND' resource for the clipboard. Once the window exists, we can then
- ** set the document size to be 7 inches by 10 inches. */
-
- #pragma segment ClipboardDoc
- static OSErr ClipboardInitContent(FileRecHndl frHndl, WindowPtr window)
- {
- #ifndef __MWERKS__
- #pragma unused (window)
- #endif
-
- SetDocSize(frHndl, (7 * 72), (10 * 72));
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Handle only document scrolling for the clipboard. */
-
- #pragma segment ClipboardDoc
- static void ClipboardContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl, firstClick)
- #endif
-
- IsCtlEvent(window, event, nil, nil);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* No keys for the clipboard. Returning true eats all of the keys, so that
- ** they aren't passed on to the next window behind the clipboard. */
-
- #pragma segment ClipboardDoc
- static Boolean ClipboardContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
- {
- #ifndef __MWERKS__
- #pragma unused (window, event, passThrough)
- #endif
-
- return(true);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* Whenever the clipboard is active, just use an arrow cursor. */
-
- #pragma segment ClipboardDoc
- static Boolean ClipboardWindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl, window, globalPt)
- #endif
-
- SetCursor(gCursorPtr = &qd.arrow);
- return(true);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Handle cut/copy/paste for the clipboard. */
-
- #pragma segment ClipboardDoc
- void DoClipboard(FileRecHndl frHndl, short menuItem)
- {
- FileRecHndl frClip;
- TreeObjHndl root, rootClip, chndl;
- short cnum;
- WindowPtr clipWind, window;
-
- if (!(clipWind = GetNextWindow(nil, kClipboardFileType))) return;
-
- frClip = (FileRecHndl)GetWRefCon(clipWind);
- rootClip = (*frClip)->d.doc.root;
- root = (*frHndl)->d.doc.root;
-
- if (menuItem != kStdCopy)
- NewDocumentUndo(frHndl);
-
- switch (menuItem) {
- case kStdCut:
- case kStdCopy:
- while ((*rootClip)->numChildren) DisposeChild(NO_EDIT, rootClip, 0);
- /* First dispose of the clipboard's old content. */
- for (cnum = (*root)->numChildren; cnum;) {
- chndl = GetChildHndl(root, --cnum);
- if (mDerefCommon(chndl)->selected) { /* If document object is selected... */
- CopyChild(NO_EDIT, root, cnum, rootClip, 0, true); /* Copy it. */
- mDerefCommon(GetChildHndl(rootClip, 0))->selected = false; /* Deselect it. */
- mDerefRoot(rootClip)->numSelected = 0;
- /* Copying the child caused it to get selected, and to increment the
- ** numSelected value in the clipboard's root. Reset it. */
- }
- }
- if (((WindowPeek)clipWind)->visible) { /* If clipboard visible... */
- BeginContent(clipWind); /* Redraw clipboard to show the new content. */
- DoImageDocument(frClip);
- EndContent(clipWind);
- }
- if (menuItem == kStdCut) /* If clipboard operation was a delete... */
- DoDelete(frHndl); /* Delete the objects out of the document. */
- break;
- case kStdPaste:
- DoTreeSelect(root, SELECTOFF); /* Turn off current document selections. */
- for (cnum = (*rootClip)->numChildren; cnum;) {
- chndl = GetChildHndl(rootClip, --cnum);
- CopyChild(CLIPBOARD_EDIT, rootClip, cnum, root, 0, true);
- /* Copy the clipboard objects with deepCopy to copy grouped objects as well. */
- }
- BeginContent(window = (*frHndl)->fileState.window); /* Redraw document. */
- DoImageDocument(frHndl);
- EndContent(window);
- break;
- }
- }
-
-
-
-